Purpose
The sort task sorts the elements of a given array and returns the sorted array. The default sort order is ascending (e.g., from A to Z or from 0 to 9). This task method changes the position of the elements in the original array.
Potential Use Case
The sort task can be used to sort arrays of numbers, strings and objects. You could use this task to arrange a list of names in alphabetical order, or a collection of dates in numerical order. For any outcome data that needs to be captured and sorted, you could potentially use sort .
Properties
Input and output properties are shown below.
| Input | Type | Description | 
|---|---|---|
| arr | Array | Required. The array to be sorted. | 
| key | String | Optional. For objects, a value used to set the sort order. | 
| limit | Number | Optional. The number of records to return. | 
| reverse | Boolean | Required. If true, the arris sorted in reverse (descending) order. Default is false (ascending order). | 
| Output | Type | Description | 
|---|---|---|
| response | Array | The output of sorting the arr. | 
Examples
Example 1
In this IAP example:
- An array of incoming reference variables for - arrare statically set:- [{"name": "cat"},{"name": "dog"},{"name": "hamster"},{"name": "ant"},{"name": "Lion"}].
 Notice the name "Lion" is uppercase.
- The - keyparameter is- name, and the record- limitis 4.
- The - reverseparameter is false (default). 
- The sort order will be ascending in the - response, with "Lion" listed first in the sorted array since it begins with a capital (uppercase) letter. 
Example 2
In this IAP example:
- An array of incoming variables for - arrare statically set. The reference variables are:- [{"car": "Audi"},{"car": "Volvo"},{"car": "Honda"},{"car": "BMW"}]. Notice all the initial letters in the names are uppercase.
- The - keyparameter is- car, and the- limitis left blank.
- The - reverseparameter is false (default). 
- The resulting sort order will be alphabetical (ascending order).  
Example 3
In this IAP example:
- An array of incoming variables for - arrare statically set. The reference variables are:- ["ant","bee","Cat","dog","Elephant"]. Notice the mix of lowercase and uppercase values.
- The - keyand- limitare left blank.
- The - reverseparameter is true. 
- The resulting sort order will be descending, with all the lowercase values listed in reverse alphabetical order followed by the uppercase values. 